import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import User from '../views/User.vue'
import Main from '../views/Main.vue'
import Mall from '../views/Mall.vue'
import Page1 from '../views/Page1.vue'
import Page2 from '../views/Page2.vue'
Vue.use(VueRouter)

// 1. 创建路由组件
// 2. 将路由与组件进行映射
// 3. 创建router实例
const routes = [
    // 主路由
    { 
        path: '/',
        component: Main,
        redirect: '/home', // 重定向
        children:[
            // 子路由
            { path: 'home', name: 'home', component: Home }, // 首页
            { path: 'user', name: 'user', component: User }, // 用户管理
            { path: 'mall', name: 'mall', component: Mall }, // 商品管理
            { path: 'Page1', name: 'Page1', component: Page1 }, // 页面1
            { path: 'Page2', name: 'Page2', component: Page2 }, // 页面2
        ]
    }
]

const router = new VueRouter({
    routes
})

export default router